@model Orchard.Users.Models.RegistrationSettingsPart
@using Orchard.Messaging.Services;
@using System.Web.Security;
@using Orchard.Users.Models;

@{
    var messageChannelSelector = WorkContext.Resolve<IMessageChannelSelector>();
    var emailEnabled = messageChannelSelector.GetChannel("Email", null) != null;
}

<fieldset>
    <legend>@T("Users")</legend>
    <div>
        @Html.EditorFor(m => m.UsersCanRegister)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.UsersCanRegister)">@T("Users can create new accounts on the site")</label>
    </div>

    <div>
        @Html.EditorFor(m => m.EnableCustomUsernamePolicy)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnableCustomUsernamePolicy)">@T("Username must meet custom requirements")</label>
        <div data-controllerid="@Html.FieldIdFor(m => m.EnableCustomUsernamePolicy)" style="margin-left: 30px;">
            <div>
                @Html.EditorFor(m => m.BypassPoliciesFromBackoffice)
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.BypassPoliciesFromBackoffice)">@T("Allow backend users to bypass the custom policies and show a warning when that happens.")</label>
            </div>
            <div>
                <label for="@Html.FieldIdFor(m => m.MinimumUsernameLength)">@T("Minimum Username length")</label>
                @Html.TextBoxFor(m => m.MinimumUsernameLength, new { @class = "text medium", @Value = Model.MinimumUsernameLength })
                <span class="hint">@T("Minimum value allowed is 1")</span>
                <span class="hint">@T("If this value is greater than the value set for Maximum Username length this setting will be ignored.")</span>
                @Html.ValidationMessage("MinimumUsernameLength", "*")
            </div>
            <div>
                <label for="@Html.FieldIdFor(m => m.MaximumUsernameLength)">@T("Maximum Username length")</label>
                @Html.TextBoxFor(m => m.MaximumUsernameLength, new { @class = "text medium", @Value = Model.MaximumUsernameLength })
                <span class="hint">@T("Maximum value allowed is {0}", UserPart.MaxUserNameLength)</span>
                <span class="hint">@T("If this value is smaller than the value set for Minimum Username length this setting will be ignored.")</span>
                @Html.ValidationMessage("MaximumUsernameLength", "*")
            </div>
            <div>
                @Html.EditorFor(m => m.ForbidUsernameWhitespace)
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.ForbidUsernameWhitespace)">@T("Username must not contain whitespaces")</label>
            </div>
            <div>
                @Html.EditorFor(m => m.ForbidUsernameSpecialChars)
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.ForbidUsernameSpecialChars)">@T("Username must not contain special characters")</label>
                <div data-controllerid="@Html.FieldIdFor(m => m.ForbidUsernameSpecialChars)" style="margin-left: 30px;">
                    @Html.EditorFor(m => m.AllowEmailAsUsername)
                    <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowEmailAsUsername)">@T("Username may be an email")</label>
                </div>
            </div>
        </div>
    </div>


    <div>
        @Html.EditorFor(m => m.EnableCustomPasswordPolicy)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnableCustomPasswordPolicy)">@T("Passwords must meet custom requirements")</label>
        <div data-controllerid="@Html.FieldIdFor(m => m.EnableCustomPasswordPolicy)" style="margin-left: 30px;">
            <div>
                <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnablePasswordLowercaseRequirement)"
                       name="@Html.FieldNameFor(m => m.EnablePasswordLowercaseRequirement)" @(Model.EnablePasswordLowercaseRequirement && Model.EnableCustomPasswordPolicy ? "checked=\"checked\"" : "") />
                <input name="@Html.FieldNameFor(m => m.EnablePasswordLowercaseRequirement)" type="hidden" value="false">
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordLowercaseRequirement)">@T("Password must contain at least one lower case letter (a-z)")</label>
            </div>
            <div>
                <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnablePasswordUppercaseRequirement)"
                       name="@Html.FieldNameFor(m => m.EnablePasswordUppercaseRequirement)" @(Model.EnablePasswordUppercaseRequirement && Model.EnableCustomPasswordPolicy ? "checked=\"checked\"" : "") />
                <input name="@Html.FieldNameFor(m => m.EnablePasswordUppercaseRequirement)" type="hidden" value="false">
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordUppercaseRequirement)">@T("Password must contain at least one upper case letter (A-Z)")</label>
            </div>
            <div>
                <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnablePasswordNumberRequirement)"
                       name="@Html.FieldNameFor(m => m.EnablePasswordNumberRequirement)" @(Model.EnablePasswordNumberRequirement && Model.EnableCustomPasswordPolicy ? "checked=\"checked\"" : "") />
                <input name="@Html.FieldNameFor(m => m.EnablePasswordNumberRequirement)" type="hidden" value="false">
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordNumberRequirement)">@T("Password must contain at least one number (0-9)")</label>
            </div>
            <div>
                <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnablePasswordSpecialRequirement)"
                       name="@Html.FieldNameFor(m => m.EnablePasswordSpecialRequirement)" @(Model.EnablePasswordSpecialRequirement && Model.EnableCustomPasswordPolicy ? "checked=\"checked\"" : "") />
                <input name="@Html.FieldNameFor(m => m.EnablePasswordSpecialRequirement)" type="hidden" value="false">
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordSpecialRequirement)">@T("Password must contain at least one special character")</label>
            </div>
            <div>
                <label for="@Html.FieldIdFor(m => m.MinimumPasswordLength)">@T("Minimum Password length")</label>
                @Html.TextBoxFor(m => m.MinimumPasswordLength, new { @class = "text medium", @Value = Model.MinimumPasswordLength })
                @Html.ValidationMessage("MinimumPasswordLength", "*")
            </div>
            <div>
                <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnablePasswordExpiration)"
                       name="@Html.FieldNameFor(m => m.EnablePasswordExpiration)" @(Model.EnablePasswordExpiration && Model.EnableCustomPasswordPolicy ? "checked=\"checked\"" : "") />
                <input name="@Html.FieldNameFor(m => m.EnablePasswordExpiration)" type="hidden" value="false">
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordExpiration)">@T("Password expires after a time period (30 days by default)")</label>
            </div>
            <div data-controllerid="@Html.FieldIdFor(m => m.EnablePasswordExpiration)" style="margin-left: 30px;">
                <label for="@Html.FieldIdFor(m => m.PasswordExpirationTimeInDays)">@T("Password expiration period in days")</label>
                @Html.TextBoxFor(m => m.PasswordExpirationTimeInDays, new { @class = "text medium", @Value = Model.PasswordExpirationTimeInDays })
                @Html.ValidationMessage("PasswordExpirationTimeInDays", "*")
            </div>
            <div>
                <label for="@Html.FieldIdFor(m => m.PasswordFormat)">@T("Password format")</label>
                @Html.DropDownListFor(m => m.PasswordFormat, new SelectList(new[]
                {
                    new SelectListItem { Text = T("Clear").Text, Value = MembershipPasswordFormat.Clear.ToString() },
                    new SelectListItem { Text = T("Hashed").Text, Value = MembershipPasswordFormat.Hashed.ToString(), Selected = true },
                    new SelectListItem { Text = T("Encrypted").Text, Value = MembershipPasswordFormat.Encrypted.ToString() }
                }, "Value", "Text"))
            </div>

            <div>
                @Html.EditorFor(m => m.EnablePasswordHistoryPolicy)
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnablePasswordHistoryPolicy)">@T("Enable password history policy")</label>
                <div data-controllerid="@Html.FieldIdFor(m => m.EnablePasswordHistoryPolicy)" style="margin-left: 30px;">
                    <label for="@Html.FieldIdFor(m => m.PasswordReuseLimit)">@T("Block reuse of last n passwords")</label>
                    @Html.TextBoxFor(m => m.PasswordReuseLimit, new { @class = "text medium", @Value = Model.PasswordReuseLimit })
                    @Html.ValidationMessage("PasswordReuseLimit", "*")
                </div>
            </div>
        </div>
        <div>
            <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.EnableLostPassword)" name="@Html.FieldNameFor(m => m.EnableLostPassword)" @(Model.EnableLostPassword ? "checked=\"checked\"" : "") @(emailEnabled ? "" : "disabled=\"disabled\"") />
            <input name="@Html.FieldNameFor(m => m.EnableLostPassword)" type="hidden" value="false">
            <label class="forcheckbox" for="@Html.FieldIdFor(m => m.EnableLostPassword)">@T("Display a link to enable users to reset their password")</label>

            @if (!emailEnabled) {
                <div class="message message-Warning">@T("This option is available when an email module is activated.")</div>
            }
        </div>
        <div>
            <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.UsersMustValidateEmail)" name="@Html.FieldNameFor(m => m.UsersMustValidateEmail)" @(Model.UsersMustValidateEmail ? "checked=\"checked\"" : "") @(emailEnabled ? "" : "disabled=\"disabled\"") />
            <input name="@Html.FieldNameFor(m => m.UsersMustValidateEmail)" type="hidden" value="false">
            <label class="forcheckbox" for="@Html.FieldIdFor(m => m.UsersMustValidateEmail)">@T("Users must verify their email address")</label>

            @if (!emailEnabled) {
                <div class="message message-Warning">@T("This option is available when an email module is activated.")</div>
            }
        </div>
        <div data-controllerid="@Html.FieldIdFor(m => m.UsersMustValidateEmail)">
            <label for="@Html.FieldIdFor(m => m.ValidateEmailRegisteredWebsite)">@T("Website public name")</label>
            @Html.TextBoxFor(m => m.ValidateEmailRegisteredWebsite, new { @class = "text medium" })
            @Html.ValidationMessage("ValidateEmailRegisteredWebsite", "*")
            <span class="hint">@T("The name of your website as it will appear in the verification e-mail.")</span>

            <label for="@Html.FieldIdFor(m => m.ValidateEmailContactEMail)">@T("Contact Us E-Mail address")</label>
            @Html.TextBoxFor(m => m.ValidateEmailContactEMail, new { @class = "text medium" })
            @Html.ValidationMessage("ValidateEmailContactEMail", "*")
            <span class="hint">@T("The e-mail address displayed in the verification e-mail for a Contact Us link. Leave empty for no link.")</span>
        </div>
        <div>
            @Html.EditorFor(m => m.UsersAreModerated)
            <label class="forcheckbox" for="@Html.FieldIdFor(m => m.UsersAreModerated)">@T("Users must be approved before they can log in")</label>
        </div>
        <div data-controllerid="@Html.FieldIdFor(m => m.UsersAreModerated)">
            <input type="checkbox" value="true" class="check-box" id="@Html.FieldIdFor(m => m.NotifyModeration)" name="@Html.FieldNameFor(m => m.NotifyModeration)" @(Model.NotifyModeration ? "checked=\"checked\"" : "") @(emailEnabled ? "" : "disabled=\"disabled\"") />
            <input name="@Html.FieldNameFor(m => m.NotifyModeration)" type="hidden" value="false">
            <label class="forcheckbox" for="@Html.FieldIdFor(m => m.NotifyModeration)">@T("Send a notification when a user needs moderation")</label>

            @if (!emailEnabled) {
                <div class="message message-Warning">@T("This option is available when an email module is activated.")</div>
            }

        </div>
        <div data-controllerid="@Html.FieldIdFor(m => m.NotifyModeration)">
            <label for="@Html.FieldIdFor(m => m.NotificationsRecipients)">@T("Moderators")</label>
            @Html.TextBoxFor(m => m.NotificationsRecipients, new { @class = "text medium" })
            @Html.ValidationMessage("NotificationsRecipients", "*")
            <span class="hint">@T("The usernames to send the notifications to (e.g., \"admin, user1, ...\").")</span>
        </div>
    </div>
</fieldset>
